//
//  MyInputViewController.m
//  OperationPro
//
//  Created by yaxue wang on 2017/1/3.
//  Copyright © 2017年 展鸿科技. All rights reserved.
//

#import "MyInputViewController.h"
#import "InputView.h"
#import "InputModel.h"
#import "MWPhotoBrowser.h"
#import "InputDetailViewController.h"
@interface MyInputViewController ()<MWPhotoBrowserDelegate>
@property(nonatomic,strong)InputView *inputView;
@property(nonatomic,strong)NSMutableArray *photosAr;
@property(nonatomic,strong)MWPhotoBrowser *homebrowser;

@end

@implementation MyInputViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"我的录入"];
    __block typeof(self) blockSelf = self;
  
    _inputView =[[InputView alloc]initWithFrame:CGRectMake(0, 64, WindowWidth, WindowHeight-64)];
    [self.view addSubview:_inputView];

#pragma mark 进入详情页首页
    [_inputView setGoToNextDetail:^(InputModel* model) {
                   
    InputDetailViewController *detailVc =[[InputDetailViewController alloc]init];
    detailVc.Uuid=model.H_uuid;
    detailVc.state=model.H_state;
    [blockSelf pushController:detailVc];
        
    }];
#pragma mark 播放语音首页
    [_inputView setPlaySound:^(InputModel* model) {
       
        
    }];
    _photosAr=[[NSMutableArray alloc]init];
#pragma mark 放大图片首页
    
    [_inputView setBlowUpImg:^(InputModel* model,NSString* num) {
       
            NSString*urlString =[CClass getCacheData:qnDomain];
            [blockSelf.photosAr removeAllObjects];
            NSString*imgStr=model.H_image;
            NSString *videoStr=model.H_video;
            
            if ((imgStr ==nil||[imgStr isEqualToString:@""])) {
                if (videoStr.length>0) {
#pragma mark 播放视频
                    
                    [blockSelf.photosAr addObject:[MWPhoto videoWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",urlString,videoStr]]]];
                }
            }else
            {
                NSArray *array = [imgStr componentsSeparatedByString:@","];
                for (int i=0; i<array.count; i++) {
                    NSURL *url =[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",urlString,[array objectAtIndex:i]]];
                    [blockSelf.photosAr addObject:[MWPhoto photoWithURL:url]];
                    
                }
                if (videoStr.length>0) {
#pragma mark 播放视频
                    
                    [blockSelf.photosAr addObject:[MWPhoto videoWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",urlString,videoStr]]]];
                }
            
            
            
            _homebrowser = [[MWPhotoBrowser alloc] initWithDelegate:blockSelf];
            // Present
            [blockSelf.navigationController pushViewController:blockSelf.homebrowser animated:YES];
            blockSelf.homebrowser.displayActionButton = NO;
            blockSelf.homebrowser.displayNavArrows = NO;
            blockSelf.homebrowser.displaySelectionButtons = NO;
            blockSelf.homebrowser.zoomPhotosToFill = YES;
            blockSelf.homebrowser.alwaysShowControls = NO;
            blockSelf.homebrowser.enableGrid = YES;
            blockSelf.homebrowser.startOnGrid = NO;
            blockSelf.homebrowser.autoPlayOnAppear = NO;
            
            [blockSelf.homebrowser setCurrentPhotoIndex:[num integerValue]];
            
            UIView *backView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 44)];
            [backView bk_whenTapped:^{
                [blockSelf.navigationController popViewControllerAnimated:YES];
            }];
            
            UIImage *icoBack = [UIImage imageNamed:@"Ico_nar_backWhite"];
            UIImageView *imgBack = [[UIImageView alloc] initWithFrame:CGRectMake(0, (40-icoBack.size.height)/2, icoBack.size.width, icoBack.size.height)];
            imgBack.image=icoBack;
            imgBack.userInteractionEnabled=YES;
            [backView addSubview:imgBack];
            
            UILabel *backTitle = [[UILabel alloc] init];
            backTitle.frame=CGRectMake(CGRectGetMaxX(imgBack.frame) + 5, 0, 50 - imgBack.frame.size.width,40);
            
            [backTitle setText:@"返回"];
            [backTitle setTextColor:[UIColor whiteColor]];
            [backTitle setFont:F(14)];
            [backView addSubview:backTitle];
            UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backView];
            blockSelf.homebrowser.navigationItem.leftBarButtonItem = leftBarButtonItem;
            
        }
        
        
    }];
    

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
